<template>
	<view style="width: 100%;">
		<view id="home" style="margin-top: 24rpx;margin-left: 30rpx;float: left;margin-bottom: 18rpx;"
			class="home acea-row row-center-wrapper iconfont icon-xiangzuo h5_back" @tap="returns">
		</view>
		<view style="width: 100%;min-height: 100vh;overflow-y: auto;">
			<view class="header">
				<view style="display: grid;">
					<image :src="listData.cover" style="width: 100%;" mode="widthFix">
					</image>
				</view>
				<view class="u-tabs-box sticky" :style="stickyStyle" v-if="listData.type == '课程'">
					<utabsswiper activeColor="#ea5550" ref="tabs" :list="list" :current="current" @change="change"
						:fontSize="24" :is-scroll="false" swiperWidth="750"></utabsswiper>
				</view>
				<view v-if="swiperCurrent == 0">
					<dsintroduction ref="dsintroduction" :bootId="bootId" :userId="userId" :token="token"
						:dyTitle="dyTitle" :hwId="hwId" class="swiper-content">
					</dsintroduction>
				</view>
				<view v-if="swiperCurrent == 1">
					<catalog class="swiper-content" :jumpId="jumpId" :hwId="hwId">
					</catalog>
				</view>
			</view>
		</view>
	</view>

</template>
<script>
	const app = getApp();
	import utabsswiper from '../portraitMaster/backup/h-tabs-swiper.vue';
	import dsintroduction from './components/dsintroduction.vue';
	import catalog from './components/catalog.vue';
	import {
		getDailyDataByType,
	} from '@/api/home.js';
	import {
		getBootcampHomework,
	} from '@/api/camp.js';

	import {
		loginMobile,
	} from "@/api/user";
	import {
		mapGetters
	} from "vuex";
	import animationType from '@/utils/animationType.js'

	export default {
		components: {
			utabsswiper,
			dsintroduction,
			catalog
		},
		data() {
			return {
				listData: {},
				current: 0,
				swiperCurrent: 0,
				list: [{
					name: '作业安排'
				}, {
					name: '课程目录'
				}],
				stickyStyle: '',
				detailHeight: 1000,
				renshi: 'https://pic.mae.vip//crmebimage/public/maintain/2025/08/28/e42d66d27f4c40e692d91ef9b4be04b2vdqrf72uer.png',
				bootId: '',
				userId: '',
				token: '',
				dyTitle: '',
				hwId: '',
				jumpId: '',
			}
		},
		created() {
			let that = this;
		},
		onLoad(options) {
			let that = this;
			that.bootId = options.bootId;
			that.userId = options.userId;
			that.token = options.token;
			that.dyTitle = options.dyTitle;
			that.hwId = options.hwId;
			that.jumpId = options.jumpId;

			console.log('!@#----------------' + options.jumpId);
		},
		mounted: function() {
			let that = this;
			//计算第一个页面的内容高度
			//that.calcSwiperHeight(that.swiperCurrent);
			// uni.$on('pageScroll', (scrollTop) => {
			// 	console.log('scrollTop=== ', scrollTop);
			// 	if (scrollTop > 300) { // 滚动超过300时吸顶
			// 		that.stickyStyle = 'position: fixed; top: 0; width: 100%; z-index: 999;';
			// 	} else {
			// 		that.stickyStyle = '';
			// 	}
			// });
			that.getList();
		},
		beforeDestroy() {
			uni.$off('pageScroll'); // 避免内存泄漏
		},
		onReachBottom() {
			let that = this;

			//console.log('onReachBottom');
			if (that.swiperCurrent == 0) {
				that.$nextTick(() => {
					that.$refs.dsintroduction.bottomGet();
				})
			}
		},
		methods: {
			returns() {
				uni.navigateBack();
			},
			getList() {
				let that = this;
				let p = {};
				p.userId = that.userId;
				p.token = that.token;
				p.id = that.hwId;
				getBootcampHomework(p).then(res => {
					if (res.code == 0) {
						that.listData = res.data;
						//把分享标题和详情发送给原生
						let platform = uni.getSystemInfoSync().platform; //手机类型
						console.log('share_title==' + that.listData.share_title)
						console.log('share_message==' + that.listData.share_message)
						// 通过检查window.android和window.webkit属性来判断是否是移动端
						if (window.webkit) {
							if (platform == 'ios') {
								let share = {
									'share_title': that.listData.share_title,
									'share_message': that.listData.share_message,
								};
								//window.webkit.messageHandlers.shareContent.postMessage(share);
							}
						}

						if (platform == 'android') {
							// window.location.href = 'shareContent?share_title=' + that.listData.share_title +
							// 	'&share_message=' + that.listData.share_message;
						}
					}
				})
			},
			change(current) {
				let that = this;
				that.$refs.tabs.setFinishCurrent(current);
				that.swiperCurrent = current;
				that.current = current;
				console.log('+++++')
			},
			transition({
				detail: {
					dx
				}
			}) {
				let that = this;
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				let that = this;
				that.$refs.tabs.setFinishCurrent(current);
				that.swiperCurrent = current;
				that.current = current;
			},
		}
	}
</script>

<style lang="scss" scoped>
	page,
	body {
		height: 100%;
		width: 100%;
		background-color: white;
	}

	.header {
		width: 100%;
		height: 280rpx;
	}
</style>